






//
//  NTalentSearchViewController.m
//  nncloud
//
//  Created by macfai on 2018/12/20.
//  Copyright © 2018 macfai. All rights reserved.
//

#import "NTalentSearchViewController.h"
#import "NMineCell.h"
#import "NTalentSearchViewController.h"
#import "NJobSeekSearchResultVC.h"
@interface NTalentSearchViewController ()<UITableViewDataSource,UITableViewDelegate,STPickerSingleDelegate,UITextFieldDelegate>
@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataArray;

@property(nonatomic,strong)NSArray *titleArray;

@property(nonatomic,strong)NSArray *pickerArray;

@property (nonatomic,assign)NSInteger index;

@property (nonatomic,strong)STPickerSingle *picker;

///行业
@property (nonatomic,copy)NSString *gender;
@property (nonatomic,copy)NSString *marrage;
@property (nonatomic,copy)NSString *age;
@property (nonatomic,copy)NSString *education;
@property (nonatomic,copy)NSString *jobNature;
@property (nonatomic,copy)NSString *experince;
@property (nonatomic,copy)NSString *industryWill;
@property (nonatomic,copy)NSString *jobWill;

///行业
@property (nonatomic,copy)NSString *genderText;
@property (nonatomic,copy)NSString *marrageText;
@property (nonatomic,copy)NSString *ageText;
@property (nonatomic,copy)NSString *educationText;
@property (nonatomic,copy)NSString *jobNatureText;
@property (nonatomic,copy)NSString *experinceText;
@property (nonatomic,copy)NSString *industryWillText;
@property (nonatomic,copy)NSString *jobWillText;

@property (nonatomic,copy)NSString *name;

@end

@implementation NTalentSearchViewController

#define cellIdentifier @"mineid"
#define SectionHeaderHeight  10.f

-(UITableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - 64) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 60.f;
        _tableView.backgroundColor = kBackgroundColor;
        [_tableView registerNib:[UINib nibWithNibName:@"NMineCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        _tableView.showsVerticalScrollIndicator = NO;
        //        _tableView.tableFooterView = [UIView new];
        
    }
    return _tableView;
}

//企业招聘
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    self.index = 0;
    [self.navigationItem setItemWithTitle:@"人才搜索" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    self.titleArray = @[@"姓名",@"性别",@"婚姻状况",@"年龄",@"学历",@"工作性质",@"工作经验",@"行业意向",@"职位意向"];
    [self.view addSubview:self.tableView];
    [self addFooter];
    // Do any additional setup after loading the view.
}

-(void)addFooter {
    
    UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 100.f)];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 20, 300, 50);
    btn.centerX = footer.centerX;
    btn.backgroundColor = ThemeBlue;
    btn.layer.cornerRadius = 5.f;
    btn.layer.masksToBounds = YES;
    [btn setTitle:@"确认搜索" forState:UIControlStateNormal];
    [btn addTarget: self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
    [footer addSubview:btn];
    self.tableView.tableFooterView = footer;
    
}

#pragma mark - 确认搜索
//确认搜索
- (void)tapAction:(UIButton *)btn{
    //跳转搜索结果页面
    NSDictionary *dict = @{@"name":self.name?:@"",@"sex":self.gender?:@"",@"marriage":self.marrage?:@"",@"age":self.age?:@"",@"edu":self.education?:@"",@"nature":self.jobNature?:@"",@"experince":self.experince?:@"",@"industry":self.industryWill?:@"",@"Job":self.jobWill?:@"",@"size":@100,@"curPage":@1,};
    NJobSeekSearchResultVC *result = [NJobSeekSearchResultVC new];
    result.dict = dict;
    [self.navigationController pushViewController:result animated:YES];
}

#pragma mark - datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return  self.titleArray.count;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NMineCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    
    cell.nameLabelLeftMargin.constant = 25.f;
    cell.nameLabel.text = self.titleArray[indexPath.section];
    cell.arrowImg.hidden = YES;
    cell.setLabel.hidden = false;
    cell.setLabel.text = @"请选择";
    
//    if (indexPath.section==0) {
//        
//        cell.setLabel.hidden = YES;
//        cell.titleTextField.hidden = false;
//        cell.textFieldLeftMargin.constant = 85.f;
//        cell.titleTextField.placeholder = @"请输入名字";
//        cell.titleTextField.delegate = self;
//        cell.titleTextField.tag = 1001;
//        
//    }
    
    switch (indexPath.section) {
        case 0:{
            cell.setLabel.hidden = YES;
            cell.titleTextField.hidden = false;
            cell.textFieldLeftMargin.constant = 85.f;
            cell.titleTextField.placeholder = @"请输入名字";
            cell.titleTextField.delegate = self;
            cell.titleTextField.tag = 1001;
        }
            break;// break 一定要写，不然会有问题的
        case 1:
        {
            if (self.gender) {
                cell.setLabel.text = self.genderText;
            }
        }
            break;
        case 2:
        {
            if (self.marrage) {
                cell.setLabel.text = self.marrageText;
            }
        }
            break;
        case 3:
        {
            if (self.age) {
                cell.setLabel.text = self.ageText;
            }
        }
            break;
        case 4:
        {
            if (self.education) {
                cell.setLabel.text = self.educationText;
            }
        }
            break;
        case 5:
        {
            if (self.jobNature) {
                cell.setLabel.text = self.jobNatureText;
            }
        }
            break;
        case 6:
        {
            if (self.experince) {
                cell.setLabel.text = self.experinceText;
            }
        }
            break;
        case 7:
        {
            if (self.industryWill) {
                cell.setLabel.text = self.industryWillText;
            }
        }
            break;
        case 8:
        {
            if (self.jobWill) {
                cell.setLabel.text = self.jobWillText;
            }
        }
            break;
      
            
        default:
            break;
    }
    return cell;
}


#pragma picker delegate

-(void)pickerSingle:(STPickerSingle *)pickerSingle selectedTitle:(NSString *)selectedTitle selectIndex:(NSInteger)selectIndex{
    YYLog(@"%@",selectedTitle);
    
    switch (pickerSingle.tag) {
            
        case 501:
        {
            //
            self.genderText = selectedTitle;
            self.gender = [NSString stringWithFormat:@"%ld",(long)selectIndex];
        }
            break;
        case 502:
        {
            self.marrageText = selectedTitle;
            self.marrage = [NSString stringWithFormat:@"%ld",(long)selectIndex];
        }
            break;
        case 503:
        {
            self.ageText = selectedTitle;
            self.age = [NSString stringWithFormat:@"%ld",(long)selectIndex];
        }
            break;
        case 504:
        {
            self.educationText = selectedTitle;
            self.education = [NSString stringWithFormat:@"%ld",(long)selectIndex];
        }
            break;
        case 505:
        {
            self.jobNatureText = selectedTitle;
            self.jobNature = [NSString stringWithFormat:@"%ld",(long)selectIndex];
        }
            break;
        case 506:
        {
            self.experinceText = selectedTitle;
            self.experince = [NSString stringWithFormat:@"%ld",(long)selectIndex];
        }
            break;
        case 507:
        {
            self.industryWillText = selectedTitle;
            self.industryWill = [NSString stringWithFormat:@"%ld",(long)selectIndex];
        }
            break;
        case 508:
        {
            self.jobWillText = selectedTitle;
            self.jobWill = [NSString stringWithFormat:@"%ld",(long)selectIndex];
        }
            break;
        default:
            break;
    }
    
    NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:self.index];
    [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
}

- (void)pickerSingle:(STPickerSingle *)pickerSingle selectedTitle:(NSString *)selectedTitle{
    
   
}

#pragma mark - delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section!=0) {
        self.index = indexPath.section;
        [self addPickerWithIndexPath: indexPath];
        [self.view endEditing:YES];
    }
    
}

///添加picker
- (void)addPickerWithIndexPath:(NSIndexPath *)indexPath{
    
    STPickerSingle *single = [[STPickerSingle alloc]init];
    [single setArrayData:[self getArrayWithIndexPath:indexPath]];
    single.tag = indexPath.section+500;
    [single setTitleUnit:@""];
    [single setDelegate:self];
    [single show];
}

#pragma mark - section head
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SectionHeaderHeight;//如果设置section的header高度，不设置footer高度，footer默认等于header高度
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SectionHeaderHeight)];
    view.backgroundColor = kBackgroundColor;
    return view;
}

#pragma mark - section foot
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}


///获取picker 数据源
- (NSMutableArray *)getArrayWithIndexPath:(NSIndexPath *)indexPath{
    
    switch (indexPath.section) {
        case 1:
        {
            self.pickerArray = @[@"男",@"女",@"不限"];
        }
            break;
        case 2:
        {
            self.pickerArray = @[@"已婚",@"未婚",@"不限"];
        }
            break;
        case 3:
        {
            //年龄
            self.pickerArray = @[@"18-25",@"26-30",@"30-35",@"36-40",@"40以上",@"不限"];
        }
            break;
        case 4:
        {
            
            self.pickerArray = @[@"初中",@"高中",@"中专",@"大专",@"本科",@"硕士",@"博士",@"不限"];
        }
            break;
        case 5:
        {
            
            self.pickerArray = @[@"全职",@"兼职",@"实习",@"不限"];
            
        }
            break;
        case 6:
        {
            //工作经验
            
            self.pickerArray = @[@"1年以上",@"2年以上",@"3年以上",@"4年以上",@"5年以上",@"6年以上",@"7年以上",@"不限"];
        }
            break;
        case 7:
        {
            
            self.pickerArray = @[@"机械装备制造",@"电子信息",@"铝深加工",@"食品加工",@"生物制药",@"清洁能源",@"其他行业",@"不限"];
            
        }
            break;
        case 8:
        {
            //工作经验
           self.pickerArray = @[@"经济管理类",@"行政/人事/后勤类",@"财务/税务/审计类",@"生产制造/工厂管理类",@"市场/销售类",@"客服/技术服务类",@"计算机/互联网类",@"科研/咨询类",@"证券/金融/投资类",@"其他类",@"不限"];
        }
            break;
            
        default:
            break;
    }
    
    return (NSMutableArray *)self.pickerArray;
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField.tag==1001) {
        self.name = textField.text;
        [self.view endEditing:YES];
    }
}
@end
